use serde::{Deserialize, Serialize};
use thiserror::Error;

// 错误类型
#[derive(Error, Debug)]
pub enum ServiceError {
    #[error("HTTP请求错误: {0}")]
    Reqwest(#[from] reqwest::Error),
    #[error("JSON序列化/反序列化错误: {0}")]
    Json(#[from] serde_json::Error),
    #[error("配置错误: {0}")]
    Config(#[from] config::ConfigError),
    #[error("URL解析错误: {0}")]
    Url(#[from] url::ParseError),
    #[error("API错误: 状态码={code}, 消息={message}")]
    Api { code: i32, message: String },
    #[error("其他错误: {0}")]
    Other(String),
}

// 通用 API 响应结构
#[derive(Debug, Serialize, Deserialize)]
pub struct ApiResponse<T> {
    pub code: i32,
    pub msg: String,
    pub data: Option<T>,
}

// 配置结构
#[derive(Debug, Deserialize)]
pub struct AppConfig {
    pub url: UrlConfig,
    pub target: TargetConfig,
}

#[derive(Debug, Deserialize)]
pub struct UrlConfig {
    pub video_visit_url_prefix: String,
    pub source_sites: String,
    pub update_site_last_check_date: String,
    pub upload_book_and_chapters: String,
    pub get_book: String,
    pub get_task: String,
    pub upload_video_slice_result: String,
}
#[derive(Debug, Deserialize)]
pub struct TargetConfig {
    pub host: String,
}

